#ifndef VIRTOOLS_MOTION_STATE_H
#define VIRTOOLS_MOTION_STATE_H

//#include "btMotionState.h"
//#include "btTransform.h"
//#include "btQuaternion.h"
#include "BulletManager.h"

class virtoolsMotionState : public btMotionState
{
public:
	virtoolsMotionState(const btTransform &virIniTrans,CK3dEntity* vir3dEntity)
		
	{
		m_graphicsWorldTrans = virIniTrans;
		m_startWorldTrans = virIniTrans;
		ent = vir3dEntity;
	}

	~virtoolsMotionState()
	{}

	virtual void	getWorldTransform(btTransform& worldTrans ) const
	{
		worldTrans = m_graphicsWorldTrans;
	}
	
	virtual void	setWorldTransform(const btTransform& worldTrans)
	{
		m_graphicsWorldTrans = worldTrans;
		btQuaternion rot = m_graphicsWorldTrans.getRotation();
		btVector3 ori = m_graphicsWorldTrans.getOrigin ();
		VxQuaternion *vquat = new VxQuaternion(rot.x(),rot.y(),-(rot.z()),rot.w());
		ent->SetQuaternion(vquat);
		//ent->SetOrientation(rot.z(),rot.y(),rot.x());
		ent->SetPosition(ori.x(),ori.y(),-(ori.z()));
	}

protected:
	btTransform m_graphicsWorldTrans;
	//btTransform	m_centerOfMassOffset;
	btTransform m_startWorldTrans;
	CK3dEntity* ent;
};

#endif //VIRTOOLS_MOTION_STATE_H